import yaml


# yaml 在线校验（编辑）网址:http://www.bejson.com/validators/yaml_editor/
# 文件的读取
def yaml_read(file_path):
    f = open(file_path, 'r', encoding='utf-8')  # r  只读
    x = yaml.load(f, yaml.FullLoader)
    y = dict()
    y['data'] = x
    f.close()
    return y


# 文件的追加写入
def yaml_a_write(file_path, data):
    f = open(file_path, 'a', encoding='utf-8')  # a 追加写入 w 覆盖写入
    yaml.dump(data, f, allow_unicode=True)
    f.close()


# 文件的覆盖写入
def yaml_w_write(file_path, data):
    f = open(file_path, 'w', encoding='utf-8')  # a 追加写入 w 覆盖写入
    yaml.dump(data, f, allow_unicode=True)
    f.close()


# 文件的更新
def yaml_update(self, file_path, data):
    x = self.yaml_read(file_path)
    x.update(data)
    self.yaml_a_write(file_path, x)

if __name__ == '__main__':
    res = yaml_read('../data/test_1b_thing_active.yaml')
    print(res)